<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>后台小类型页面</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="/after/css/bootstrap.min.css?v=3.4.0" rel="stylesheet">
    <link href="/after/css/font-awesome.min.css?v=4.3.0" rel="stylesheet">
    <link href="/after/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="/after/css/animate.min.css" rel="stylesheet">
    <link href="/after/css/style.min.css?v=3.0.0" rel="stylesheet">

    <link href="/after/js/laypage/skin/laypage.css" rel="stylesheet">
    <!--引用vue的js-->
    <script src="/after/js/vue/vue.min.js"></script>
    <!--分页插件-->
    <script src="/after/js/laypage/laypage.js" charset="utf-8"></script>
    <script src="/after/js/layer/layer.js" charset="utf-8"></script>


    <script src="/after/js/jquery-2.1.1.min.js" type="text/javascript"></script>
    <script src="/after/js/bootstrap.min.js?v=3.4.0" type="text/javascript"></script>
    <script type="text/javascript" src="/after/js/Globals.js"></script>
    <script type="text/javascript" src="/after/js/websocket.js"></script>
    <script type="text/javascript" src="/after/js/vue/vue.min.js"></script>
    <script src="/after/js/layer/layer.js" charset="utf-8"></script>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight" id="app">
    <br>
    <br>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <h2>权限操作</h2>
                <div class="ibox-title" id="bt">
                    <input type="button" value="搜索" onclick="getRolePageList();"/>
                    <input type="text" id="type" name="name" style="text-align: right"/><br>
                </div>
                <div class="ibox-title" id="jiedian"></div>
                <div class="ibox-content">
                    <table class="table table-striped table-bordered table-hover " id="editable">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>名称</th>
                            <th>权限</th>
                            <th colspan="3" style="text-align: center">操作</th>
                            <th>登录状态</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr class="active" v-for="(item,index) in result">
                            <td>{{item.id}}</td>
                            <td>{{item.name}}</td>
                            <td>{{item.role.role}}</td>
                            <td>
                                <a href="javascript:;" @click="editEvent(item.id)">编辑</a>
                            </td>
                            <td>
                                <a href="javascript:;" @click="delEvent(item.id)">删除</a>
                            </td>
                            <td>
                                <a href="javascript:;" @click="ChangePass(item.id)">修改密码</a>
                            </td>
                            <td>
                                {{item.line}}
                                <span v-if="item.line=='在线'"><a @click="quit(item.name)" style="float:right;">踢下线</a></span>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <div id="pagenav"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    var app = new Vue({
        el : '#app',
        data : {
            result : []
        }
    });

    $(function(){
        getRolePageList();
    })
    var getRolePageList = function(curr) {
        $.ajax({
            url:"/role/findAll.do",
            type:"post",
            dataType:"JSON",
            data : {
                pageNum:curr || 1,
                pageSize:3,
                name:$("#type").val()
            },
            error:function () {
                alert("错误");
            },
            success:function (msg) {
                app.result=msg.page;
                var str =  '${online}'.split(',');
                for(i=0;i<app.result.length;i++){
                    for(j=0;j<str.length;j++){
                        if(str[j]==app.result[i].name){
                            app.result[i].line = "在线";
                            break;
                        }else{
                            app.result[i].line = "不在线";
                        }
                    }
                }
                console.log(app.result);
                laypage({
                    cont : 'pagenav', //容器。值支持id名、原生dom对象，jquery对象,
                    pages : msg.totalPage, //总页数
                    skin:'#FFFFFF',
                    first : '首页',
                    last : '尾页',
                    curr : curr || 1, //当前页
                    jump : function(obj, first) { //触发分页后的回调
                        if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                            getRolePageList(obj.curr);
                        }
                    }
                });
            }
        });
    }


    <!--删除-->
    function delEvent(obj){
        if(confirm("确认删除吗？")){
            $.ajax({
                url:"/role/deleteRole.do",
                type:'post',
                dataType:'json',
                data:{
                    id:obj
                },
                error:function () {
                    alert("错误");
                },
                success:function (msg) {
                    getRolePageList();
                }
            })
        }
    }

    //编辑数据_查
    var editEvent = function (id) {
        layer.open({
            type: 2,
            title: '编辑权限',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['500px', '200px'],
            content: '/role/updateRole_Find.do?id='+id,
            end: function () {
                getRolePageList();
            }
        });
    }


    //编辑数据_查
    var ChangePass = function (id) {
        layer.open({
            type: 2,
            title: '修改密码',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['500px', '500px'],
            content: '/backstage/ChangePass.ftl?id='+id,
            end: function () {
                getRolePageList();
            }
        });
    }

    //踢下线
    var quit = function(obj){
        $.ajax({
            type:"GET",
            dataType:"json",
            url:"/web/quit.do",
            data:{
                name:obj
            },success:function(msg){
                alert(msg.result);
                location.reload();
            }
        })
    }
</script>
</body>
</html>